package cn.edu.neusoft.demo.hospital2.Controller;

import cn.edu.neusoft.demo.hospital2.Service.DepartmentService;
import cn.edu.neusoft.demo.hospital2.pojo.Department;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

// ... existing code ...
@RestController
@Tag(name = "DepartmentController相关的api")
@CrossOrigin(origins = "*")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    // 查询所有科室
    @RequestMapping("/getAllDepartments")
    public List<Department> getAllDepartments(){
        return departmentService.getDepartments();
    }

    // 根据ID查询科室
    @GetMapping("/department/{departmentId}")
    public Department getDepartmentById(@PathVariable int departmentId){
        return departmentService.getDepartmentById(departmentId);
    }

    // 新增科室
    @PostMapping("/department")
    public int addDepartment(@RequestBody Department department){
        return departmentService.addDepartment(department);
    }

    // 更新科室信息
    @PutMapping("/department")
    public int updateDepartment(@RequestBody Department department){
        return departmentService.updateDepartment(department);
    }

    // 删除科室
    @DeleteMapping("/department/{departmentId}")
    public int deleteDepartment(@PathVariable int departmentId){
        return departmentService.deleteDepartment(departmentId);
    }
}


